#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int num;
    char **pt;

    int i;

    printf("字符串个数: ");
    scanf("%d", &num);

    pt = (char **)calloc(num , sizeof(char *));

    for (i=0; i<num; ++i)
        pt[i] = NULL;

    i=0;
    if (pt == NULL) {
        puts("存储空间分配失败!");

    } else {
        for (;i<num; ++i) {
            char tmp[127];
            scanf("%s", tmp);

            int len = strlen(tmp);
            pt[i] = malloc(len + 1);

            if (pt[i] == NULL) {
                puts("存储空间分配失败");
                break;

            } else {
                strcpy(pt[i], tmp);
            }
        }
    }

    if (i != num) {
        for (i=0; i<num; ++i)
            free(pt[i]);
        free(pt);

    } else {
        for (i=0; i<num; ++i)
            printf("p[%d] : %s\n", i, pt[i]);
    }

    return 0;
}
